<script setup lang="ts">
import {
  Container,
  LocalObjectReference,
  SecretType
} from "@/views/domain/kubeHud/api/k8s/types";
import KSecretSelect from "../../secret/widgets/KSecretSelect.vue";
import { computed } from "vue";

const container = defineModel<Container>("container");
const imagePullSecrets =
  defineModel<LocalObjectReference[]>("imagePullSecrets");

const pullSecret = computed<string>({
  get() {
    if (imagePullSecrets.value && imagePullSecrets.value.length > 0) {
      return imagePullSecrets.value[0].name;
    }
    return "";
  },
  set(value) {
    imagePullSecrets.value = [{ name: value }];
  }
});
</script>

<template>
  <el-form :model="container" label-width="120px" label-position="top">
    <el-form-item label="名称" prop="name">
      <el-input v-model="container.name" />
    </el-form-item>
    <el-row :gutter="20">
      <el-col :span="24">
        <el-form-item label="容器镜像" prop="image">
          <el-input v-model="container.image">
            <template #prepend>
              <KSecretSelect
                v-model:model-value="pullSecret"
                :type="SecretType.DockerConfigJson"
                style="width: 150px"
              />
            </template>
          </el-input>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<style lang="scss" scoped></style>
